local skel = fk.CreateSkill {
  name = "emo__yuge",
}

Fk:loadTranslationTable{
  ["emo__yuge"] = "渔歌",
  [":emo__yuge"] = "其他角色的回合开始时，你可以弃置X张手牌（X为你至其的距离），若如此做，此回合内你不为锦囊牌的合法目标，当前回合结束时，你获得弃牌堆中其本回合失去的所有非装备牌。",

  ["#emo__yuge"] = "渔歌：你可弃%arg张手牌，%dest 回合结束时，你获得弃牌堆中其本回合失去的所有非装备牌",
  ["@@emo__yuge-turn"] = "渔歌",
}

skel:addEffect(fk.TurnStart, {
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(skel.name) and not player:isKongcheng() and not player:isRemoved() and not target:isRemoved()
  end,
  on_cost = function (self, event, target, player, data)
    local x = player:distanceTo(target)
    local cards = player.room:askToDiscard(player, {
      min_num = x, max_num = x, include_equip = false, skill_name = skel.name, pattern = ".|.|.|hand",
      prompt = "#emo__yuge::"..target.id..":"..x, skip = true
    })
    if #cards == x then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@emo__yuge-turn", target.id)
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
  end,
})

skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getMark("@@emo__yuge-turn") == target.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == target then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile and Fk:getCardById(info.cardId).type ~= Card.TypeEquip then
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #ids > 0 then
      room:obtainCard(player, ids, true, fk.ReasonPrey, player, skel.name)
    end
  end,
})

skel:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return card and card.type == Card.TypeTrick and to and to:getMark("@@emo__yuge-turn") ~= 0
  end,
})

return skel
